<html>
<head><meta charset="utf-8"><title>Removing assignment as a way to get () values · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Removing.20assignment.20as.20a.20way.20to.20get.20().20values.html">Removing assignment as a way to get () values</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="194746155"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Removing%20assignment%20as%20a%20way%20to%20get%20%28%29%20values/near/194746155" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Removing.20assignment.20as.20a.20way.20to.20get.20().20values.html#194746155">(Apr 20 2020 at 23:38)</a>:</h4>
<p>I some wrote code <em>as recently as today</em> that involved doing <code>Ok(self.val = new_val)</code> as the last line of a function to trim away having <code>Ok(())</code> as its own line, examples: <a href="https://gist.github.com/rust-play/9c506790bbce761c59c8b7419fd293be" title="https://gist.github.com/rust-play/9c506790bbce761c59c8b7419fd293be">https://gist.github.com/rust-play/9c506790bbce761c59c8b7419fd293be</a></p>
<p>So please don't invalidate that.</p>



<a name="194759088"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Removing%20assignment%20as%20a%20way%20to%20get%20%28%29%20values/near/194759088" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Removing.20assignment.20as.20a.20way.20to.20get.20().20values.html#194759088">(Apr 21 2020 at 04:03)</a>:</h4>
<p>That seems rather inscrutable.</p>



<a name="194759152"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Removing%20assignment%20as%20a%20way%20to%20get%20%28%29%20values/near/194759152" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Removing.20assignment.20as.20a.20way.20to.20get.20().20values.html#194759152">(Apr 21 2020 at 04:05)</a>:</h4>
<p>Also, you should be getting a warning about "otherwise" being unused.</p>



<a name="194759776"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Removing%20assignment%20as%20a%20way%20to%20get%20%28%29%20values/near/194759776" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Removing.20assignment.20as.20a.20way.20to.20get.20().20values.html#194759776">(Apr 21 2020 at 04:25)</a>:</h4>
<p>Yes, otherwise is unused at the moment. If this becomes the final form of the function and i don't end up braking apart the error conditions more then i'll put an underscore on the name. Until then about half the project just has <code>allow(unused)</code> on it.</p>



<a name="194759962"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Removing%20assignment%20as%20a%20way%20to%20get%20%28%29%20values/near/194759962" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Removing.20assignment.20as.20a.20way.20to.20get.20().20values.html#194759962">(Apr 21 2020 at 04:31)</a>:</h4>
<p>Also, the code seems fairly clear to me. Though I am the author so naturally I'd end up being more comfortable with it.</p>
<p>I'd say that in general I like code that's visually compact, so I end up making things a little different from normal.</p>
<p>For example, in other parts of the same project I write <code>try_from</code> instances like this:</p>
<div class="codehilite"><pre><span></span><span class="k">impl</span><span class="w"> </span><span class="n">TryFrom</span><span class="o">&lt;</span><span class="kt">u8</span><span class="o">&gt;</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">PngColorType</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="k">type</span> <span class="nc">Error</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">PngError</span><span class="p">;</span><span class="w"></span>
<span class="w">  </span><span class="cp">#[must_use]</span><span class="w"></span>
<span class="w">  </span><span class="cp">#[inline(always)]</span><span class="w"></span>
<span class="w">  </span><span class="k">fn</span> <span class="nf">try_from</span><span class="p">(</span><span class="n">color</span>: <span class="kt">u8</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nb">Result</span><span class="o">&lt;</span><span class="n">Self</span><span class="p">,</span><span class="w"> </span><span class="n">PngError</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="nb">Ok</span><span class="p">(</span><span class="k">match</span><span class="w"> </span><span class="n">color</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">      </span><span class="mi">0</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">PngColorType</span>::<span class="n">Greyscale</span><span class="p">,</span><span class="w"></span>
<span class="w">      </span><span class="mi">2</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">PngColorType</span>::<span class="n">Truecolor</span><span class="p">,</span><span class="w"></span>
<span class="w">      </span><span class="mi">3</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">PngColorType</span>::<span class="n">Indexed</span><span class="p">,</span><span class="w"></span>
<span class="w">      </span><span class="mi">4</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">PngColorType</span>::<span class="n">GreyscaleAlpha</span><span class="p">,</span><span class="w"></span>
<span class="w">      </span><span class="mi">6</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">PngColorType</span>::<span class="n">TruecolorAlpha</span><span class="p">,</span><span class="w"></span>
<span class="w">      </span><span class="n">_</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="nb">Err</span><span class="p">(</span><span class="n">PngError</span>::<span class="n">IllegalColorType</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">color</span><span class="w"> </span><span class="p">}),</span><span class="w"></span>
<span class="w">    </span><span class="p">})</span><span class="w"></span>
<span class="w">  </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>


<p>and it all feels quite natural to me.</p>



<a name="194761228"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Removing%20assignment%20as%20a%20way%20to%20get%20%28%29%20values/near/194761228" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kennytm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Removing.20assignment.20as.20a.20way.20to.20get.20().20values.html#194761228">(Apr 21 2020 at 05:06)</a>:</h4>
<p>if we follow RFC 2443 you should still be able to use <code>Ok((self.val = new_val))</code> or <code>Ok({ self.val = new_val })</code>. and <code>Ok(self.val = new_val)</code> is already warned by <code>clippy::unit_arg</code>.</p>



<a name="194773329"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Removing%20assignment%20as%20a%20way%20to%20get%20%28%29%20values/near/194773329" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Removing.20assignment.20as.20a.20way.20to.20get.20().20values.html#194773329">(Apr 21 2020 at 08:29)</a>:</h4>
<p>I'd use clippy more but rust-analyzer doesn't really seem to support it, and i generally want RA support more than clippy support</p>



<a name="194830683"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Removing%20assignment%20as%20a%20way%20to%20get%20%28%29%20values/near/194830683" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Removing.20assignment.20as.20a.20way.20to.20get.20().20values.html#194830683">(Apr 21 2020 at 16:51)</a>:</h4>
<p><span class="user-mention silent" data-user-id="224471">Lokathor</span> <a href="#narrow/stream/213817-t-lang/topic/Removing.20assignment.20as.20a.20way.20to.20get.20().20values/near/194746155" title="#narrow/stream/213817-t-lang/topic/Removing.20assignment.20as.20a.20way.20to.20get.20().20values/near/194746155">said</a>:</p>
<blockquote>
<p>So please don't invalidate that.</p>
</blockquote>
<p>I feel like that's arguably a feature request for Ok-wrapping :)</p>



<a name="194853863"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Removing%20assignment%20as%20a%20way%20to%20get%20%28%29%20values/near/194853863" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Removing.20assignment.20as.20a.20way.20to.20get.20().20values.html#194853863">(Apr 21 2020 at 20:01)</a>:</h4>
<p>Yes, you could read it like that. If there was a better way to have Ok-wrapping happen then I also wouldn't mind a change.</p>



<a name="194918861"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Removing%20assignment%20as%20a%20way%20to%20get%20%28%29%20values/near/194918861" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Charles Lew <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Removing.20assignment.20as.20a.20way.20to.20get.20().20values.html#194918861">(Apr 22 2020 at 11:54)</a>:</h4>
<p>I feel there's some correspondence between "keyword arguments" and "field initializers", it would be nice if they can use same symbols.</p>



<a name="194919007"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Removing%20assignment%20as%20a%20way%20to%20get%20%28%29%20values/near/194919007" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Charles Lew <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Removing.20assignment.20as.20a.20way.20to.20get.20().20values.html#194919007">(Apr 22 2020 at 11:56)</a>:</h4>
<p>Aside from "=", maybe ":=" is a nice choice too :)</p>



<a name="194985019"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Removing%20assignment%20as%20a%20way%20to%20get%20%28%29%20values/near/194985019" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Removing.20assignment.20as.20a.20way.20to.20get.20().20values.html#194985019">(Apr 22 2020 at 20:09)</a>:</h4>
<p>I recall that <span class="user-mention silent" data-user-id="256841">Nick Cameron</span> felt that <code>Foo { x = y }</code> would have been a better choice of syntax.</p>



<a name="194985026"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Removing%20assignment%20as%20a%20way%20to%20get%20%28%29%20values/near/194985026" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Removing.20assignment.20as.20a.20way.20to.20get.20().20values.html#194985026">(Apr 22 2020 at 20:09)</a>:</h4>
<p>Bit late for that.</p>



<a name="194985061"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Removing%20assignment%20as%20a%20way%20to%20get%20%28%29%20values/near/194985061" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Removing.20assignment.20as.20a.20way.20to.20get.20().20values.html#194985061">(Apr 22 2020 at 20:09)</a>:</h4>
<p>It is, though I do wonder if it might be possible to introduce one day. :)</p>



<a name="194985120"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Removing%20assignment%20as%20a%20way%20to%20get%20%28%29%20values/near/194985120" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Removing.20assignment.20as.20a.20way.20to.20get.20().20values.html#194985120">(Apr 22 2020 at 20:10)</a>:</h4>
<p>So, so much better :)</p>



<a name="194985153"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Removing%20assignment%20as%20a%20way%20to%20get%20%28%29%20values/near/194985153" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Removing.20assignment.20as.20a.20way.20to.20get.20().20values.html#194985153">(Apr 22 2020 at 20:10)</a>:</h4>
<p><code>:</code> for field assignments conflicts with several other syntax proposals IIRC.</p>



<a name="194985163"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Removing%20assignment%20as%20a%20way%20to%20get%20%28%29%20values/near/194985163" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Removing.20assignment.20as.20a.20way.20to.20get.20().20values.html#194985163">(Apr 22 2020 at 20:10)</a>:</h4>
<p>Alas.</p>



<a name="194998531"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Removing%20assignment%20as%20a%20way%20to%20get%20%28%29%20values/near/194998531" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Removing.20assignment.20as.20a.20way.20to.20get.20().20values.html#194998531">(Apr 22 2020 at 22:23)</a>:</h4>
<p><span class="user-mention" data-user-id="116458">@Charles Lew</span> We currently (conceptually) have "tuple struct literals" sharing syntax with "positional-argument function calls"; I've been pondering whether we could just have "named struct literal" syntax also be used for "named-argument function calls"...</p>



<a name="194998805"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Removing%20assignment%20as%20a%20way%20to%20get%20%28%29%20values/near/194998805" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Removing.20assignment.20as.20a.20way.20to.20get.20().20values.html#194998805">(Apr 22 2020 at 22:26)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span> We _could_ introduce it whenever we want, right?  I don't think <code>ident { ident =</code> in expression position is a conflict, since the preceding ident distinguishes it from a block with an assignment.  (Weighing the churn being a completely different conversation, of course.)</p>



<a name="195000114"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Removing%20assignment%20as%20a%20way%20to%20get%20%28%29%20values/near/195000114" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Removing.20assignment.20as.20a.20way.20to.20get.20().20values.html#195000114">(Apr 22 2020 at 22:42)</a>:</h4>
<p>Right. It could be a stylistic choice, if we wanted it to be and felt it wouldn't be confusing.</p>



<a name="195000189"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Removing%20assignment%20as%20a%20way%20to%20get%20%28%29%20values/near/195000189" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Removing.20assignment.20as.20a.20way.20to.20get.20().20values.html#195000189">(Apr 22 2020 at 22:43)</a>:</h4>
<p>There's very little benefit in having it be a stylistic choice: the primary reason to switch is to eliminate the ambiguity with things like type ascription.</p>



<a name="195000279"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Removing%20assignment%20as%20a%20way%20to%20get%20%28%29%20values/near/195000279" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Removing.20assignment.20as.20a.20way.20to.20get.20().20values.html#195000279">(Apr 22 2020 at 22:44)</a>:</h4>
<p>Phasing it out slowly would not be ideal; you would probably want to switch on an edition change and rustfix it.</p>



<a name="195000346"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Removing%20assignment%20as%20a%20way%20to%20get%20%28%29%20values/near/195000346" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Removing.20assignment.20as.20a.20way.20to.20get.20().20values.html#195000346">(Apr 22 2020 at 22:45)</a>:</h4>
<p>(It could be an interesting experiment to take a large codebase, and see what it looked like with <code>=</code> instead of <code>:</code>.)</p>



<a name="195008134"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Removing%20assignment%20as%20a%20way%20to%20get%20%28%29%20values/near/195008134" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Removing.20assignment.20as.20a.20way.20to.20get.20().20values.html#195008134">(Apr 23 2020 at 00:40)</a>:</h4>
<p>Seems like it is <em>probably</em> a fairly straightforward change to make in the parser, so at least in theory we could land that and then rustfix rust-lang/rust or so.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>